<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>编辑管理员信息</title>
    <meta name="编辑用户信息" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="../../css/font.css">
    <link rel="stylesheet" href="../../css/xadmin.css">
    <script type="text/javascript" src="../../lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>

    <!-- 引入公用JavaScript -->
    <script src="../../js/jquery.min.js"></script>
    <script src="../../js/app.js"></script>
    <script src="https://cdn.bootcss.com/moment.js/2.23.0/moment.min.js" type="text/javascript" charset="utf-8">
    </script>

    <!-- my JavaScript -->
    <script type="text/javascript" src="./manager-data.js"></script>
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-row">
            <form class="layui-form">
                <div class="layui-form-item">
                    <label for="manager" class="layui-form-label">
                        <span class="x-red">*</span>管理员名称</label>
                    <div class="layui-input-inline">
                        <input type="text" id="manager" name="manager" required="" lay-verify="manager"
                            autocomplete="off" class="layui-input"></div>
                </div>
                <div class="layui-form-item">
                    <label for="timeLimit" class="layui-form-label">
                        <span class="x-red">*</span>管理员有效期</label>
                    <div class="layui-input-inline">
                        <input type="text" id="timeLimit" name="timeLimit" class="layui-input" placeholder="yyyy-MM-dd">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="maxNum" class="layui-form-label">
                        <span class="x-red">*</span>用户上限数</label>
                    <div class="layui-input-inline">
                        <input type="text" id="maxNum" name="maxNum" required="" lay-verify="maxNum" autocomplete="off"
                            class="layui-input"></div>
                </div>

                <div class="layui-form-item">
                    <label for="workId" class="layui-form-label">
                        <span class="x-red">*</span>管理员工号</label>
                    <div class="layui-input-inline">
                        <input type="text" id="workId" name="workId" required="" lay-verify="workId" autocomplete="off"
                            class="layui-input"></div>
                </div>
                <div class="layui-form-item">
                    <label for="tmpNum" class="layui-form-label">
                        <span class="x-red">*</span>已创用户数</label>
                    <div class="layui-input-inline">
                        <input type="text" id="tmpNum" name="tmpNum" required="" lay-verify="tmpNum"
                               autocomplete="off" class="layui-input"></div>
                </div>
                <div class="layui-form-item">
                    <label for="L_repass" class="layui-form-label"></label>
                    <button id="submit" type="button" class="layui-btn" lay-filter="save" lay-submit="save">保存</button></div>

            </form>
        </div>
    </div>
    <script>
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            $(this).removeAttr("lay-key");
            laydate.render({
                elem: '#timeLimit',
                trigger : 'click'
            })
        })

        /* 父页面获取传过来的id */
        var thisURL = document.URL;
        var getval = thisURL.split('?')[1];
        var managerId = getval.split("=")[1];

        $.ajax({
            url: app.ServerUrl + "v1/user/selectManagerById?managerId=" + managerId,
            dataType: "json",
            type: "get",
            async: false,
            data: {},
            headers: {
                "Authorization": "460bcdb0-b326-4d6d-ac99-232c83ba6d80"
            },
            success: function (responseData) {
                var result = responseData.objs[0];
                var manager = result.manager;
                var timeLimit = app.getFormatDate(result.timeLimit);
                var maxNum = result.maxNum;
                var workId = result.workId;
                var tmpNum = result.tmpNum;

                // 表格中的默认数据渲染
                $("#manager").val(manager);
                $("#timeLimit").val(timeLimit);
                $("#maxNum").val(maxNum);
                $("#workId").val(workId);
                $("#tmpNum").val(tmpNum);

            },
            error: function (error) {
                layer.msg('网络错误', {
                    icon: 5,
                    time: 1000
                })
            }
        })



        layui.use(['form', 'layer'],
            function () {
                $ = layui.jquery;
                var form = layui.form,
                    layer = layui.layer;

                //自定义验证规则
                form.verify({
                    nikename: function (value) {
                        if (value.length < 2) {
                            return '姓名至少得2个字符啊';
                        }
                    }
                });

                //监听提交
                form.on('submit(save)',
                    function (data) {

                        // 编辑用户Ajax
                        $.ajax({
                            url: app.ServerUrl + 'v1/user/updateManagerById?managerId=' + managerId,
                            type: 'post',
                            dataType: 'json',
                            async: false,
                            data: data.field,
                            success: function () {
                                layer.msg('修改成功', {
                                    icon: 1,
                                    time: 1000
                                })
                            },
                            error: function (res) {
                                layer.msg(res.resultIns, {
                                    icon: 5,
                                    time: 1000
                                })
                            }

                        });

                    });
            });
    </script>
    <script>
        var _hmt = _hmt || [];
        (function () {
            var hm = document.createElement("script");
            hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
            var s = document.getElementsByTagName("script")[0];
            s.parentNode.insertBefore(hm, s);
        })();
    </script>

</body>

</html>